package com.baidu.sggc.core.common;

import java.util.Arrays;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.experimental.Accessors;

@Getter
@Accessors(fluent = true)
@AllArgsConstructor
public enum ResultCodeEnum {
  Fail(-1, "失败"),
  SUCCESS(200, "成功"),
  UNAUTHORIZED_ERROR(401, "Token为空或已过期"),
  FORBIDDEN_ERROR(403, "无权限"),
  INTERNAL_ERROR(500, "服务内部错误");

  Integer code;
  String desc;

  public static ResultCodeEnum valueOf(int code) {
    return Arrays.stream(ResultCodeEnum.values()).filter(c -> c.code == code).findFirst()
        .orElse(INTERNAL_ERROR);
  }
}
